import datetime

strategy_map = {
    'okex_lm_spot': [{
        'from_date': datetime.datetime.strptime('20180725', '%Y%m%d'),
        'exchange': 'Okex',
        'market_type': 'Spot',
        'machine': 'strategy-07.aliyun-cn-hongkong',
        'max_pos': {
            'BTC': 0.3 * 18,
            'EOS': 200 * 18,
            'ETH': 3 * 18,
            'LTC': 5 * 18,
            'ETC': 15 * 10,
            'BCH': 2 * 18,
            'TRX': 11000 * 5,
            'QTUM': 25 * 10
        }
    }]
}


class SpotPnlSetting(object):
  def __init__(self, strategy_setting):
    self.exchange = strategy_setting['exchange']
    self.market_type = strategy_setting['market_type']
    self.machine = strategy_setting['machine']
    self.max_pos_map = strategy_setting['max_pos']

  @staticmethod
  def from_name(strategy_name, as_of_date):
    assert strategy_name in strategy_map
    strat_list = sorted(strategy_map[strategy_name], key=lambda x: x['from_date'])
    for strategy_setting in strat_list:
      if strategy_setting['from_date'] < as_of_date:
        return SpotPnlSetting(strategy_setting)
    raise ValueError((strategy_name, as_of_date))
